﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


using HGZP.BLL;
using HGZP.Model;
using System.Data;

namespace SZCB.admin.FoodManager
{
    public partial class FoodClass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            /*string bookGuid = Request.QueryString["guid"];
            if (string.IsNullOrEmpty(bookGuid))
            {
                ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('参数错误');window.location.href='BookList.aspx';</script>");
                return;
            }
            if (IsPostBack == false)
            {
                BindBook(bookGuid);
                ViewState["wheresql"] = " sGuidWorkBook='" + bookGuid + "' ";
                GetContentCount();
                BindContentData();
                GetVideoCount();
                BindVideoData();
            }*/

            if (IsPostBack == false)
            {
                ViewState["wheresql"] = "";
                GetContentCount();
                BindContentData();

            }

        }

        #region 绑定食品大类信息
        /// <summary>
        /// 绑定大类信息
        /// </summary>
        private void BindFoodClass()
        {
            var foodBll = new CsFoodClassBLL();
            RptData.DataSource = foodBll.F01_SelectAll();
            RptData.DataBind();


        }
        #endregion

        #region 绑定内容表单()
        private void GetContentCount()
        {
            string sql = " ";
            if (ViewState["wheresql"] != null)
                sql += ViewState["wheresql"].ToString();
            var foodClassBll = new CsFoodClassBLL();
            returnDataPager.RecordCount = foodClassBll.F09_GetCount(sql);
        }
        private void BindContentData()
        {
            string sql = " ";
            if (ViewState["wheresql"] != null)
                sql += ViewState["wheresql"].ToString();
            var foodClassBll = new CsFoodClassBLL();
            RptData.DataSource = foodClassBll.F08_SelectColumnHaveWhereOrder_OnePage(returnDataPager.StartRecordIndex - 1, returnDataPager.PageSize, "*", sql, foodClassBll.dCreateDate + " DESC");
            RptData.DataBind();
        }
        protected void ReturnDataPagerPageChanged(object sender, EventArgs e)
        {
            BindContentData();
        }
        #endregion

        #region 内容信息批量删除
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbtnDelete_Click(object sender, EventArgs e)
        {
            /*string strBenefitsBook = string.Empty;
            for (int i = 0; i < RptData.Items.Count; i++)
            {
                CheckBox checkBox = (CheckBox)RptData.Items[i].FindControl("cbCheck");
                Literal literal = (Literal)RptData.Items[i].FindControl("ltrsGuid");
                if (checkBox.Checked)
                {
                    if (!string.IsNullOrEmpty(literal.Text))
                    {
                        strBenefitsBook += literal.Text + ",";
                    }
                }
            }
            if (string.IsNullOrEmpty(strBenefitsBook))
            {
                Public.globalErrorString = "请选择你要设置优惠的图书！";
                Tip_Web.Tip();
                return;
            }
            string[] benefitsBooks = strBenefitsBook.Split(',');
            var contentBll = new CWorkBookContentBLL();
            int iSuccess = benefitsBooks.Where(benefitsBook => !string.IsNullOrEmpty(benefitsBook)).Count(contentBll.F_Delete);
            Public.globalErrorString = "成功删除资源内容" + iSuccess + "个";
            Tip_Web.Tip();
            GetContentCount();
            BindContentData();*/
        }
        #endregion

        #region 视频信息批量删除
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbtnVideoDel_Click(object sender, EventArgs e)
        {
          /*  string strBenefitsBook = string.Empty;
            for (int i = 0; i < RptVideo.Items.Count; i++)
            {
                CheckBox checkBox = (CheckBox)RptVideo.Items[i].FindControl("cbCheck");
                Literal literal = (Literal)RptVideo.Items[i].FindControl("ltrsGuid");
                if (checkBox.Checked)
                {
                    if (!string.IsNullOrEmpty(literal.Text))
                    {
                        strBenefitsBook += literal.Text + ",";
                    }
                }
            }
            if (string.IsNullOrEmpty(strBenefitsBook))
            {
                Public.globalErrorString = "请选择你要设置优惠的图书！";
                Tip_Web.Tip();
                return;
            }
            string[] benefitsBooks = strBenefitsBook.Split(',');
            var videoBll = new CWorkBookContentVideoBLL();
            int iSuccess = benefitsBooks.Where(benefitsBook => !string.IsNullOrEmpty(benefitsBook)).Count(videoBll.F_Delete);
            Public.globalErrorString = "成功删除资源内容" + iSuccess + "个";
            Tip_Web.Tip();
            GetVideoCount();
            BindVideoData();*/
        }
        #endregion

        protected void RptData_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                /*Label lblClassName = e.Item.FindControl("lblClassName") as Label;
                string sqlAll = "select count(sWorkBookGuid) as number from BaseReadBook ";

                sqlAll += " where sWorkBookGuid='" + hfBookGuid.Value + "'";
                DataTable dtAllClick = myCBaseReadBookBLL.F05_SelectByCommandText(sqlAll);
                if (dtAllClick.Rows.Count > 0)
                {
                    lblAllClickNum.Text = dtAllClick.Rows[0][0].ToString();
                }*/

                Repeater rp = e.Item.FindControl("Repeater1") as Repeater;
                CFoodSubClassBLL myCFoodSubClassBLL = new CFoodSubClassBLL();
                DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项 
                rp.DataSource = myCFoodSubClassBLL.F02_SelectHaveWhere("sClassGuid='" + rowv["sGuid"].ToString() + "'");
                rp.DataBind();
            }

        }


        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {

                Repeater rp = e.Item.FindControl("Repeater2") as Repeater;
                CFoodProductBLL myCFoodProductBLL = new CFoodProductBLL();
                DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项 
                rp.DataSource = myCFoodProductBLL.F02_SelectHaveWhere("sSubClassGuid='" + rowv["sGuid"].ToString() + "'" );
                rp.DataBind();
            }

        }

    }
}